package client.states;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;

import client.IGameState;
import client.Player;
import client.StateContext;
import client.World;
import client.XMLLoaders.LevelLoader;

import com.jpemartin.jgt.KeyboardStatus;

public class ExploreScreen implements IGameState {

	private Player player;
	private int moveSpeed = 1;
	private Image areaBackground;
	private World world;

	public ExploreScreen(Player player, World world) {
		this.player = player;
		this.world = world;
		LevelLoader levelLoader = new LevelLoader("Levels.xml", world);
		player.setCurrentArea(world.getArea(0, 0));
	}

	public World getWorld(){
		return world;
	}
	
	@Override
	public void paint(Graphics g, StateContext stateContext, int GameTime) {
		player.getCurrentArea().paint(g);
		player.paint(g);
	}

	@Override
	public void processKeyHit(StateContext stateContext, KeyboardStatus status) {
		if (status.key[KeyEvent.VK_ENTER]) {
			status.key[KeyEvent.VK_ENTER] = false;
			stateContext.setState(new PauseScreen(player, this));
		}
		if (status.key[KeyEvent.VK_RIGHT]) {
			player.move(moveSpeed, 0);
			if(player.getX()>390){
				player.setX(-10);
				player.setCurrentArea(world.getArea(player.getCurrentArea().getWorldX()+1, player.getCurrentArea().getWorldY()));
			}
		}
		if (status.key[KeyEvent.VK_LEFT]) {
			player.move(-moveSpeed, 0);
			if(player.getX()<10){
				player.setX(390);
				player.setCurrentArea(world.getArea(player.getCurrentArea().getWorldX()-1, player.getCurrentArea().getWorldY()));
			}
		}
		if (status.key[KeyEvent.VK_DOWN]) {
			player.move(0, moveSpeed);
		}
		if (status.key[KeyEvent.VK_UP]) {
			player.move(0, -moveSpeed);
		}
	}

}
